package com.ugtss.busniess.service.impl;


import com.ugtss.busniess.domain.Student;
import com.ugtss.busniess.mapper.StudentMapper;
import com.ugtss.busniess.service.StudentService;
import com.ugtss.common.core.domain.entity.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentMapper studentMapper;

    @Override
    public List<Student> selectStudentList(Student student) {
        return studentMapper.selectStudentList(student);
    }

    @Override
    public Boolean saveOrUpdateStudent(Student student) {
        if (student.getStudentId()!=null){
            return studentMapper.update(student) == 1;
        }else {
            Student studentByUserId = studentMapper.getStudentByUserId(student.getUserId());
            if (studentByUserId != null){
                throw new RuntimeException("该账号已经绑定过学生信息");
            }
            return studentMapper.save(student) == 1;
        }
    }

    @Override
    public Student getStudentByUserId(Integer id) {
        return studentMapper.getStudentByUserId(id);
    }

    @Override
    public Boolean deleteById(Integer id) {
        return studentMapper.deleteById(id) == 1;
    }
}

